#pragma once

#include "Cus_protocol.hpp"

void Network_Computing(Protocol::Reponse *rep, const Protocol::Requst &req)
{
    int x = req.GetLfetOperand();
    char op = req.GetOperator();
    int y = req.GetRightOperand();
    switch (op)
    {
    case '+':
        rep->Getresult() = x + y;
        break;
    case '-':
        rep->Getresult() = x - y;
        break;
    case '*':
        rep->Getresult() = x * y;
        break;
    case '/':
    {
        if (y == 0)
        {
            cout << "Divide by Zero Error" << endl;
            rep->Geterrorcode() = -1;
            rep->Getresult() = INT32_MAX;
        }
        rep->Getresult() = x / y;
    }
        break;
    case '%':
    {
        if (y == 0)
        {
            cout << "Demodulation error" << endl;
            rep->Geterrorcode() = -1;
            rep->Getresult() = INT32_MAX;
        }
        rep->Getresult() = x % y;
    }
        break;
    default:
        cout << "Operator is a non allowed character! ! !" << endl;
        rep->Geterrorcode() = -2;
        rep->Getresult() = INT32_MAX;
        break;
    }
}